<?php

namespace Proj\ResManBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Proj\ResmanBundle\Helper\GenerationHelper;

use Proj\ResManBundle\Entity\Project;
use Proj\ResManBundle\Entity\Activity;
use Proj\ResManBundle\Entity\AcademicProgram;
use Proj\ResManBundle\Entity\Task;
use Proj\ResManBundle\Entity\Resources;
use Proj\ResManBundle\Entity\TaskResources;
use Proj\ResManBundle\Form\ProjectsType;
use Proj\ResManBundle\Form\ActivityType;
use Proj\ResManBundle\Form\TaskType;
use Proj\ResManBundle\Form\ProgramType;
use Proj\ResManBundle\Form\ProjectUpdateType;

/**
 * @Route("/headmaster")
 */
class HeadMasterController extends Controller
{
    /**
     * @Route("/projects", name="headmaster_get_projects")
     */
    public function projectsAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $user = $this->get('security.context')->getToken()->getUser();
        $persoana = $user->getPerson();
        $departament = $persoana->getDepartment();
        $projects = $em->getRepository('ProjResManBundle:Project')->findBy(array('department' => $departament->getId()));
        
        $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . "/app_dev.php";
        $content_array = array("submenu" => $this->getLinksArray($baseurl));
        
        return $this->render(
            'ProjResManBundle:HeadMaster:get_projects.html.twig',
            array('projects' => $projects, 
                  'template_content' => $this->getTemplateContent($baseurl, $content_array)
            )
        );  
    }
    
    /**
     * @Route("/projects/details", name="headmaster_project_details")
     */
    public function projectDetailsAction(Request $request) {
        $em = $this->getDoctrine()->getManager();
        
        $request = $this->getRequest();
        $id = $request->query->get("project_id");
        $project = $em->getRepository('ProjResManBundle:Project')->find($id);
        $form = $this->createForm(new ProjectUpdateType(), $project);
        
        $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . "/app_dev.php";
        $content_array = array("submenu" => $this->getLinksArray($baseurl));
        
        if ($request->getMethod() == 'POST') {
            $form->bindRequest($request);
            if ($form->isValid()) {
                $em->persist($project);
                $em->flush(); //se introduce efectiv in baza de date
                $this->get('session')->setFlash('projDetails-notice', 'Proiectul a fost modificat cu succes.');
                
                return $this->redirect($this->generateUrl('headmaster_project_details', array('project_id' => $id)));
            }
        }
        
        return $this->render(
            'ProjResManBundle:HeadMaster:project_details.html.twig',
            array('form' => $form->createView(), 
                  'id' => $id,
                  'template_content' => $this->getTemplateContent($baseurl, $content_array)
            )
        );
    }
    
    /**
     * @Route("/projects/add", name="headmaster_projects_add")
     */
    public function projectsAddAction() {
        $user = $this->get('security.context')->getToken()->getUser();
        $persoana = $user->getPerson();
        $departament = $persoana->getDepartment();
        $project = new Project();
        
        $form = $this->createForm(new ProjectsType(), $project);
        $request = $this->getRequest();
        
        $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . "/app_dev.php";
        $content_array = array("submenu" => $this->getLinksArray($baseurl));
        $dateError = false;
        if ($request->getMethod() == 'POST') {
            $form->bindRequest($request);
            if ($form->isValid()) {
                date_default_timezone_set('Europe/Bucharest');
                $project->setCreationDate(new \DateTime());
                $project->setDepartment($departament);
                $project->setState('0');
                $em = $this->getDoctrine()->getManager();
                
                if ($project->getStartDate() > $project->getEndDate()) {
                    $dateError = true;
                }
                
                if (!$dateError) {
                    $project->setApproved(false);
                    $em->persist($project);
                    $em->flush();

                    $this->get('session')->getFlashBag()->add('proj-notice', 'Proiectul a fost adaugat cu succes.');

                    return $this->redirect($this->generateUrl('headmaster_projects_add'));
                }
            }
        }
        
        return $this->render(
            'ProjResManBundle:HeadMaster:projects_add.html.twig',
            array('form' => $form->createView(),
                'dateError' => $dateError,
                'template_content' => $this->getTemplateContent($baseurl, $content_array)
            )
        );
    }
   
    /**
     * @Route("/projects/delete", name="headmaster_projects_delete")
     */
    public function projectsDeleteAction() {
        $id = $this->getRequest()->query->get('project_id');
        $em = $this->getDoctrine()->getManager();
        
        $project = $em->getRepository('ProjResManBundle:Project')->find($id);
        
        $em->remove($project);
        $em->flush();
       
        return $this->redirect($this->generateUrl('headmaster_get_projects'));
    }
    
    /**
     * @Route("projects/approve/{id}", requirements={"id" = "\d+"}, name="headmaster_projects_approve")
     */
    public function projectsApproveAction($id) {
        $em = $this->getDoctrine()->getManager();
            
        $project = $em->getRepository('ProjResManBundle:Project')->find($id);
        $project->setApproved(true);

        $em->persist($project);
        $em->flush();
        
        return $this->redirect($this->generateUrl('headmaster_get_projects'));
    }
   
    /**
     * @Route("/activities", name="headmaster_activities")
     */
    /*public function activitiesAction() {
        $id = $this->getRequest()->query->get('project_id');
        $em = $this->getDoctrine()->getManager();
        $project = $em->getRepository('ProjResManBundle:Project')->find($id);
        
        return $this->render(
             'ProjResManBundle:HeadMaster:activities.html.twig',
             array('activities' => $project->getActivities())
        );
    }*/
    
    /**
     * @Route("/projects/activities", name="headmaster_get_activities")
     */
    public function getProjectActivitiesAction() {
        $request = $this->getRequest();
        $em = $this->getDoctrine()->getManager();
        $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . "/app_dev.php";
        $content_array = array("submenu" => $this->getLinksArray($baseurl));
        
        $projectId = $request->query->get("project_id");
        $project = $em->getRepository('ProjResManBundle:Project')->find($projectId);
        $activities = $project->getActivities();
        
        return $this->render(
            'ProjResManBundle:Headmaster:get_activities.html.twig',
            array('activities' => $activities,
                  'projectId' => $projectId,
                  'template_content' => $this->getTemplateContent($baseurl, $content_array)
            )
        );
    }
    
    /**
     * @Route("/projects/activities/details", name="headmaster_activity_details")
     */
    public function projectsActivitiesDetailsAction() {
        $em = $this->getDoctrine()->getManager();
        $request = $this->getRequest();
        
        $activityId = $request->query->get('activity_id');
        $activity = $em->getRepository('ProjResManBundle:Activity')->find($activityId);
        $form = $this->createForm(new ActivityType(), $activity);
        $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . "/app_dev.php";
        $content_array = array("submenu" => $this->getLinksArray($baseurl));
        
        if ($request->getMethod() == 'POST') {
            $form->bindRequest($request);
            
            if ($form->isValid()) {
                $em->persist($activity);
                $em->flush();
                
                $this->get('session')->getFlashBag()->add('activity-notice', 'Activitatea a fost modificata cu succes.');
                
                return $this->redirect($this->generateUrl('headmaster_activity_details', array('activity_id' => $activityId)));
            }
        }
        
        return $this->render(
            'ProjResManBundle:HeadMaster:activity_details.html.twig',
            array('form' => $form->createView(),
                'activityId' => $activityId,
                'projectId' => $activity->getProject()->getId(),
                'template_content' => $this->getTemplateContent($baseurl, $content_array)
            )
        );
    }
    
    /**
    * @Route("projects/activities/remove", name="headmaster_activity_remove")
    */
    public function projectsActivitiesRemoveAction() {
        $em = $this->getDoctrine()->getManager();

        $activityId = $this->getRequest()->query->get('activity_id');
        $activity = $em->getRepository('ProjResManBundle:Activity')->find($activityId);
        $projectId = $activity->getProject()->getId();

        $em->remove($activity);
        $em->flush();
        
        return $this->redirect($this->generateUrl('headmaster_get_activities', 
                array('project_id' => $projectId)
                )
        );
    }
    
    /**
     * @Route("projects/activities/add", name="headmaster_activity_add")
     */
    public function projectsActivitiesAddAction() {
        $em = $this->getDoctrine()->getManager();
        $request = $this->getRequest();
        
        $activity = new Activity();
        $form = $this->createForm(new ActivityType(), $activity);
        $projectId = $request->query->get('project_id');
        $project = $em->getRepository('ProjResManBundle:Project')->find($projectId);
        $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . "/app_dev.php";
        $content_array = array("submenu" => $this->getLinksArray($baseurl));
        
        if ($request->getMethod() == 'POST') {
            $form->bindRequest($request);
            
            if ($form->isValid()) {
                $activity->setProject($project);
                date_default_timezone_set('Europe/Bucharest');
                $activity->setCreationDate(new \DateTime());
                $activity->setApproved(false);
                
                $em->persist($activity);
                $em->flush();
                
                $this->get('session')->getFlashBag()->add('activity-notice', 'Activitatea a fost adaugata cu succes.');
                
                return $this->redirect($this->generateUrl('headmaster_activity_add', array('project_id' => $projectId)));
            }
        }
        
        return $this->render(
            'ProjResManBundle:HeadMaster:activity_add.html.twig',
            array('form' => $form->createView(),
                'projectId' => $projectId,
                'template_content' => $this->getTemplateContent($baseurl, $content_array)
            )
        );
    }
    
    /**
     * @Route("/projects/activities/approve", name="headmaster_activity_approve")
     */
    public function projectsActivityApproveAction() {
        $request = $this->getRequest();
        $em = $this->getDoctrine()->getManager();
            
        $activityId = $request->query->get('activity_id');
        $projectId = $request->query->get('project_id');
        $activity = $em->getRepository('ProjResManBundle:Activity')->find($activityId);
        $activity->setApproved(true);

        $em->persist($activity);
        $em->flush();
        
        return $this->redirect($this->generateUrl('headmaster_get_activities', array('project_id' => $projectId)));
    }
    
    /**
     * @Route("/tasks", name="headmaster_tasks")
     */
    public function tasksAction() {
        $request = $this->getRequest();
        $em = $this->getDoctrine()->getManager();
        
        $id = $this->getRequest()->query->get('activity_id');
        $activity = $em->getRepository('ProjResManBundle:Activity')->find($id);
        $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . "/app_dev.php";
        $content_array = array("submenu" => $this->getLinksArray($baseurl));
        
        return $this->render(
            'ProjResManBundle:HeadMaster:tasks.html.twig',
            array('tasks' => $activity->getTasks(), 'activityId' => $id, 'template_content' => $this->getTemplateContent($baseurl, $content_array))
        );
        /*return $this->redirect($this->generateUrl('headmaster_get_projects'),
                array('template_content' => $this->getTemplateContent($baseurl, $content_array)
            ));*/
    }
    
     /**
     * @Route("/tasks/details", name="headmaster_tasks_details")
     */
    public function taskDetailsAction() {
        $em = $this->getDoctrine()->getManager();
        $request = $this->getRequest();
        
        $activityId = $request->query->get("activity_id");
        $taskId = $request->query->get("task_id");
        $task = $em->getRepository('ProjResManBundle:Task')->find($taskId);
        $activity = $em->getRepository('ProjResManBundle:Activity')->find($activityId);
        $form = $this->createForm(new TaskType(), $task);
        $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . "/app_dev.php";
        $content_array = array("submenu" => $this->getLinksArray($baseurl));
        
        if ($request->getMethod() == 'POST') {
            $form->bindRequest($request);
            
            if ($form->isValid()) {
                $task->setCreatedDate(new \DateTime());
                $task->setActivity($activity);
                
                $em->persist($task);
                $em->flush();
                
                $this->get('session')->getFlashBag()->add('task-notice', 'Task-ul a fost modificat cu succes.');
                
                return $this->redirect($this->generateUrl('headmaster_tasks_details', array('activity_id' => $activityId, 'task_id' => $taskId)));
            }
        }
        
        return $this->render(
            'ProjResManBundle:HeadMaster:task_details.html.twig',
            array('form' => $form->createView(),
                'activityId' => $activityId,
                'taskId' => $taskId,
                'template_content' => $this->getTemplateContent($baseurl, $content_array)
            )
        );
    }
    
    /**
     * @Route("/tasks/delete", name="headmaster_tasks_delete")
     */
    public function tasksDeleteAction() {
        $request = $this->getRequest();
        $em = $this->getDoctrine()->getManager();        
        $activityId = $request->query->get('activity_id');
        $taskId = $request->query->get('task_id');
        $task = $em->getRepository('ProjResManBundle:Task')->find($taskId);
        $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . "/app_dev.php";
        $content_array = array("submenu" => $this->getLinksArray($baseurl));
        
        $em->remove($task);
        $em->flush();
       
        return $this->redirect($this->generateUrl('headmaster_tasks', array('activity_id' => $activityId, 'template_content' => $this->getTemplateContent($baseurl, $content_array))));
    }
    
    /**
     * @Route("tasks/add", name="headmaster_tasks_add")
     */
    public function tasksAddAction() {
        $em = $this->getDoctrine()->getManager();
        $request = $this->getRequest();
        
        $task = new Task();
        $form = $this->createForm(new TaskType(), $task);
        $activityId = $request->query->get('activity_id');
        $activity = $em->getRepository('ProjResManBundle:Activity')->find($activityId);
        $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . "/app_dev.php";
        $content_array = array("submenu" => $this->getLinksArray($baseurl));
        
        if ($request->getMethod() == 'POST') {
            $form->bindRequest($request);
            
            if ($form->isValid()) {
                $task->setActivity($activity);
                date_default_timezone_set('Europe/Bucharest');
                $task->setCreatedDate(new \DateTime());
                
                $em->persist($task);
                $em->flush();
                
                $this->get('session')->getFlashBag()->add('task-notice', 'Task-ul a fost adaugat cu succes.');
                
                return $this->redirect($this->generateUrl('headmaster_tasks_add', array('activity_id' => $activityId)));
            }
        }
        
        return $this->render(
            'ProjResManBundle:HeadMaster:tasks_add.html.twig',
            array('form' => $form->createView(),
                'activityId' => $activityId,
                'template_content' => $this->getTemplateContent($baseurl, $content_array)
            )
        );
    }
    
    /**
     * @Route("tasks/details/people", name="headmaster_tasks_people")
     */
    public function tasksDetailsPeopleAction() {
        $request = $this->getRequest();
        $em = $this->getDoctrine()->getManager();
        
        $activityId = $request->query->get('activity_id');
        $taskId = $request->query->get('task_id');
        $task = $em->getRepository('ProjResManBundle:Task')->find($taskId);
        $people = $task->getPeople();
        $allPeople = $em->getRepository('ProjResManBundle:Person')->findAll();
        $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . "/app_dev.php";
        $content_array = array("submenu" => $this->getLinksArray($baseurl));
        
        return $this->render(
            'ProjResManBundle:HeadMaster:tasks_details_people.html.twig',
            array('people' => $people,
                'allPeople' => $allPeople,
                'activityId' => $activityId,
                'taskId' => $taskId,
                'template_content' => $this->getTemplateContent($baseurl, $content_array)
            )
        );
    }
    
    /**
     * @Route("tasks/details/other", name="headmaster_tasks_other")
     */
    public function tasksDetailsOtherAction() {
        $request = $this->getRequest();
        $em = $this->getDoctrine()->getManager();
        
        $user = $this->get('security.context')->getToken()->getUser();
        $persoana = $user->getPerson();
        $departament = $persoana->getDepartment();
        
        $activityId = $request->query->get('activity_id');
        $taskId = $request->query->get('task_id');
        $task = $em->getRepository('ProjResManBundle:Task')->find($taskId);
        $taskResources = $em->getRepository('ProjResManBundle:TaskResources')->findBy(array('task' => $task));
        $allResources = $em->getRepository('ProjResManBundle:Resources')->findBy(array('department' => $departament->getId()));
        $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . "/app_dev.php";
        $content_array = array("submenu" => $this->getLinksArray($baseurl));
        
        return $this->render(
            'ProjResManBundle:HeadMaster:tasks_details_other.html.twig',
            array('taskResources' => $taskResources,
                'allResources' => $allResources,
                'activityId' => $activityId,
                'taskId' => $taskId,
                'template_content' => $this->getTemplateContent($baseurl, $content_array)
            )
        );
    }
    
    /**
     * @Route("tasks/details/people/add", name="headmaster_details_people_add")
     */
    public function tasksDetailsPeopleAddAction() {
        $request = $this->getRequest();
        $em = $this->getDoctrine()->getManager();
        
        $taskId = $request->query->get('task_id');
        $activityId = $request->query->get('activity_id');
        $task = $em->getRepository('ProjResManBundle:Task')->find($taskId);
        $personId = $request->query->get('person_id');
        $person = $em->getRepository('ProjResManBundle:Person')->find($personId);
        
        $taskPeople = $task->getPeople();
        if (!$taskPeople->contains($person)) {
            $task->addPerson($person);
            $em->persist($task);
            $em->flush();
        }
        
        return $this->redirect($this->generateUrl('headmaster_tasks_people', array('task_id' => $taskId, 'activity_id' => $activityId)));
    }
    
    /**
     * @Route("tasks/details/people/remove", name="headmaster_details_people_remove")
     */
    public function tasksDetailsPeopleRemoveAction() {
        $request = $this->getRequest();
        $em = $this->getDoctrine()->getManager();
        
        $taskId = $request->query->get('task_id');
        $activityId = $request->query->get('activity_id');
        $task = $em->getRepository('ProjResManBundle:Task')->find($taskId);
        $personId = $request->query->get('person_id');
        $person = $em->getRepository('ProjResManBundle:Person')->find($personId);
        
        $task->removePerson($person);
        $em->persist($task);
        $em->flush();
        
        return $this->redirect($this->generateUrl('headmaster_tasks_people', array('task_id' => $taskId, 'activity_id' => $activityId)));
    }
    
    /**
     * @Route("tasks/details/other/add", name="headmaster_details_other_add")
     */
    public function tasksDetailsOtherAddAction() {
        $request = $this->getRequest();
        $em = $this->getDoctrine()->getManager();
        
        
        $taskId = $request->query->get('task_id');
        $task = $em->getRepository('ProjResManBundle:Task')->find($taskId);
        $resourceId = $request->query->get('resource_id');
        $resource = $em->getRepository('ProjResManBundle:Resources')->find($resourceId);
        $amount = $request->query->get('amount');
        $taskResource = $em->getRepository('ProjResManBundle:TaskResources')->findOneBy(array('task' => $task, 'resources' => $resource));
        
        if ($taskResource == null) {
            $taskResource = new TaskResources();
            $taskResource->setTask($task);
            $taskResource->setResources($resource);
            if ($amount != null) {
                $taskResource->setAmount($amount);
            }
        } else {
            if ($amount != null) {
                $taskResource->setAmount($taskResource->getAmount() + $amount);
            }
        }
        
        $em->persist($taskResource);
        $em->flush();
        
        return $this->redirect($this->generateUrl('headmaster_tasks_other', array('task_id' => $taskId)));
    }    
    
    /**
     * @Route("tasks/details/other/remove", name="headmaster_details_other_remove")
     */
    public function tasksDetailsOtherRemoveAction() {
        $request = $this->getRequest();
        $em = $this->getDoctrine()->getManager();

        
        $taskId = $request->query->get('task_id');
        $task = $em->getRepository('ProjResManBundle:Task')->find($taskId);
        $taskResourceId = $request->query->get('taskresource_id');
        $taskResource = $em->getRepository('ProjResManBundle:TaskResources')->find($taskResourceId);
        
        $em->remove($taskResource);
        $em->flush();
        
        return $this->redirect($this->generateUrl('headmaster_tasks_other', array('task_id' => $taskId)));
    }
    
     /**
     * @Route("/academicprograms", name="headmaster_get_academicprograms")
     */
    public function getAcademicProgramsAction() {
        $request = $this->getRequest();
        $em = $this->getDoctrine()->getManager();
        $programs = $em->getRepository('ProjResManBundle:AcademicProgram')->findAll();
      
        return $this->render(
            'ProjResManBundle:Headmaster:get_programs.html.twig',
            array('programs' => $programs)
        );
    }
    
    /**
     * @Route("/academicprograms/add", name="headmaster_academicprogram_add")
     */
    public function programsAddAction() {
        
        $program = new AcademicProgram();
        
        $form = $this->createForm(new ProgramType(), $program);
        $request = $this->getRequest();
        
        if ($request->getMethod() == 'POST') {
            $form->bindRequest($request);
            if ($form->isValid()) {
                $em = $this->getDoctrine()->getManager();
                
                $em->persist($program);
                $em->flush();
              
                $this->get('session')->setFlash('prog-notice', 'Programul de studiu a fost adaugat cu succes.');
                
                return $this->redirect($this->generateUrl('headmaster_academicprogram_add'));
            }
        }
        
        return $this->render(
            'ProjResManBundle:HeadMaster:programs_add.html.twig',
            array('form' => $form->createView())
        );
    }
    
    /**
     * @Route("/resourcesreport", name="headmaster_resources_report")
     */
    public function resourcesReportAction() {
        $user = $this->get('security.context')->getToken()->getUser();
        $persoana = $user->getPerson();
        $departament = $persoana->getDepartment();
        $em = $this->getDoctrine()->getManager();
        $departmentMembers = $em->getRepository('ProjResManBundle:Person')->findBy(array('department' => $departament->getId()));    
        $projects = $em->getRepository('ProjResManBundle:Project')->findBy(array('department' => $departament->getId()));
     
        return $this->render(
             'ProjResManBundle:HeadMaster:resources_reports.html.twig',
             array('departmentMembers' => $departmentMembers, 'projects'=> $projects)
        );
    }
    
    /**
     * @Route("/resourcesreport/members", name="headmaster_resources_report_members")
     */
    public function membersResourcesReportAction() {
        $request = $this->getRequest();
        $id = $request->query->get("person_id");
        $em = $this->getDoctrine()->getManager();
        $persoana = $em->getRepository('ProjResManBundle:Person')->find($id);
        $resources = $em->getRepository('ProjResManBundle:Resources')->findByPerson($persoana);
        
        return $this->render(
             'ProjResManBundle:HeadMaster:resources_members.html.twig',
             array('resources' => $resources)
        );
    }
    
    /**
     * @Route("/resourcesreport/projects", name="headmaster_resources_report_projects")
     */
    public function projectsResourcesReportAction() {
        $request = $this->getRequest();
        $id = $request->query->get("project_id");
        $em = $this->getDoctrine()->getManager();
        $project = $em->getRepository('ProjResManBundle:Project')->find($id);
        $resources = $em->getRepository('ProjResManBundle:Resources')->findByProject($project);
        
        return $this->render(
             'ProjResManBundle:HeadMaster:resources_projects.html.twig',
             array('resources' => $resources)
        );
    }
   
    
    private function getTemplateContent($baseurl, $content_array) {
        
        $securityContext = $this->container->get('security.context');
        $token = $securityContext->getToken();
        $user = $token->getUser();
        $roles = "";

        $menu = array(
            "public" => "$baseurl/public/index",
            "admin" => "$baseurl/admin/index",
            "director" => "$baseurl/director/index",
            "cadre" => "$baseurl/cadre/index",
            "login" => "$baseurl/login",
            "logout" => "$baseurl/logout",
        );

        $text = array(
            "login" => "Log-in",
            "logout" => "Log-out",
        );

        $auth = array(
            "user" => $user,
            "isAuth" => $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED'),
            "roles" => $roles
        );

        $header_content = array(
            "menu" => $menu,
            "text" => $text
        );

        $template_content = array(
            "header" => $header_content,
            "content" => $content_array,
            "footer" => array(),
            "auth" => $auth
        );
        
        return $template_content;
    }
    
    private function getLinksArray($baseurl){
        return array (
            1 => array("href" => "$baseurl/headmaster/academicprograms", 
                       "title" => "Programe",
                       "title_desc" => "Programe de studiu"),
            2 => array("href" => "$baseurl/headmaster/projects", 
                       "title" => "Granturi",
                       "title_desc" => "Granturi de cercetare"),
            3 => array("href" => "$baseurl/headmaster/projects", 
                       "title" => "Evenimente",
                       "title_desc" => "Evenimente administrative"),
            4 => array("href" => "$baseurl/headmaster/resourcesreport",
                       "title" => "Rapoarte",
                       "title_desc" => "Vizualizeaza rapoarte resurse"),
        );
    }

}